package com.itheima.Demo3Stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo3
{
    public static void main(String[] args) {
        List<Double> list=new ArrayList<>();
        list.add(1.0);
        list.add(2.0);
        list.add(3.0);
        list.add(5.0);
        list.add(4.0);
        //升序
        list.stream().sorted().forEach(s-> System.out.println(s));
        //降序
        list.stream().sorted((s1,s2)->Double.compare(s2,s1)).forEach(s-> System.out.println(s));
        //limit 获取前几个元素
        list.stream().sorted().limit(2).forEach(s-> System.out.println(s));
        //跳过前几个元素
        list.stream().sorted().skip(2).forEach(s-> System.out.println(s));
        //distinct 去重
        list.stream().sorted().distinct().forEach(s-> System.out.println(s));
        //加工 映射方法 把流上的元素映射为另一个元素
        list.stream().map(s->s*2).forEach(s-> System.out.println(s));
        System.out.println("-----------------------------------------------------------------------");
        Stream<String> stream=Stream.of("张三","李四","王五","赵六","张三","王五");
        Stream<Integer>stream1=Stream.of(1,2,3,4,5,6);
        //合并流
        Stream<Object> stream2 = Stream.concat(stream, stream1);
        stream2.forEach(s-> System.out.println(s));
        //将流收集到一个list集合中
        List<Integer> list1=stream1.collect(Collectors.toList());
        //将流收集到一个数组中
        Integer[] array=stream1.toArray(Integer[]::new);
    }
}
